Ext.define('cceaf.control.sms.SelectAddressBookTree',{
		extend: 'Ext.Panel', 
    alias: 'widget.selectaddressbooktree',

		constructor: function(config){
			config = config || {};

	    var tree = new Ext.tree.Panel({
	    	id:'selectAddressBookTree',
	        autoScroll:true,
	        animate:true,
	        enableDD:true,
	        containerScroll: true,
	        anchor:'100% -30',
	        listeners:{
        		'itemclick':function(view,record){
	        		var selectAddressBookTree = Ext.get('selectAddressBookTree');
	        		if(selectAddressBookTree.idOfNodeid != null && selectAddressBookTree.idOfNodeid != ''){
        				var nodeid = Ext.getCmp(selectAddressBookTree.idOfNodeid);
        				nodeid.setValue(record.data.id);
	        		}
	        		if(selectAddressBookTree.idOfNodename != null && selectAddressBookTree.idOfNodename != ''){
        				var nodename = Ext.getCmp(selectAddressBookTree.idOfNodename);
        				nodename.setValue(record.data.text);
	        		}

		           	var selectAddressBookWin = Ext.getCmp('selectAddressBookWin');
		    		if(selectAddressBookWin){
	    				selectAddressBookWin.hide();
		    		}
        		}
     		},

	        root: {
	            expanded: true,
	            text: '地址簿',
	        	draggable:false,
	        	id:''
	        },

	        store: new Ext.data.TreeStore({
	            proxy: {
	                type: 'ajax',
	                url: '/' + cceaf.Global.WEB_APP_NAME + '/smsmanager/findTreeNodeListAddressBook.action'
	            },
	            sorters: [{
			          property: 'leaf',
			          direction: 'ASC'
			      }, {
			          property: 'text',
			          direction: 'ASC'
			        }
			    ]
	        })
	    });

	    var operateArea = new Ext.Panel({
	        width:150,
	        anchor:'100%',
	        layout:'column',
	        items:[
	        		{xtype: 'button',text: ' 关  闭 ',pressed: true,width: 70,handler: function(){
				      		var selectAddressBookWin = Ext.getCmp('selectAddressBookWin');
							    if(selectAddressBookWin){
							    		selectAddressBookWin.hide();
							    }
	            }},
	            {html: '',width: 10},
	            {xtype: 'button',text: ' 清  空 ',pressed: true,width: 70,
	            		handler: function(){
	               			var selectAddressBookTree = Ext.get('selectAddressBookTree');
	               			if(selectAddressBookTree.idOfNodeid != null && selectAddressBookTree.idOfNodeid != ''){
	    	        				var nodeid = Ext.getCmp(selectAddressBookTree.idOfNodeid);
	    	        				nodeid.setValue('');
	    	        		}
	    	        		if(selectAddressBookTree.idOfNodename != null && selectAddressBookTree.idOfNodename != ''){
	    	        				var nodename = Ext.getCmp(selectAddressBookTree.idOfNodename);
	    	        				nodename.setValue('');
	    	        		}

	              		var selectAddressBookWin = Ext.getCmp('selectAddressBookWin');
					    			if(selectAddressBookWin){
					    					selectAddressBookWin.hide();
					    			}
	              	}
	            }]
	    });

		config = Ext.applyIf(config || {}, {
	        layout:'anchor',
	        autoScroll:true,
	        items:[operateArea,tree]
		});

		cceaf.control.sms.SelectAddressBookTree.superclass.constructor.apply(this, arguments);
	}
});
